package com.ruoyi.bussiness.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bussiness.mapper.CcyHistoryPriceMapper;
import com.ruoyi.bussiness.domain.CcyHistoryPrice;
import com.ruoyi.bussiness.service.ICcyHistoryPriceService;

/**
 * 历史数据Service业务层处理
 * 
 * @author wzy
 * @date 2025-10-21
 */
@Service
public class CcyHistoryPriceServiceImpl implements ICcyHistoryPriceService
{
    @Autowired
    private CcyHistoryPriceMapper ccyHistoryPriceMapper;

    /**
     * 查询历史数据
     * 
     * @param id 历史数据主键
     * @return 历史数据
     */
    @Override
    public CcyHistoryPrice selectCcyHistoryPriceById(Long id)
    {
        return ccyHistoryPriceMapper.selectCcyHistoryPriceById(id);
    }

    /**
     * 查询历史数据列表
     * 
     * @param ccyHistoryPrice 历史数据
     * @return 历史数据
     */
    @Override
    public List<CcyHistoryPrice> selectCcyHistoryPriceList(CcyHistoryPrice ccyHistoryPrice)
    {
        String tableName = "ccy_history_price_day";
        String bar = ccyHistoryPrice.getBar();
        if(!StringUtils.isBlank(bar)){
            if("5m,15m,30m".contains(bar)){
                tableName = "ccy_history_price_"+bar+"in";
            }else if("1h".equals(bar)){
                tableName = "ccy_history_price_1h";
            }else if("1m".equals(bar)){
                tableName = "ccy_history_price_1m_"+ new SimpleDateFormat("yyyyMM").format(new Date());
            }
        }
        ccyHistoryPrice.setTableName(tableName);
        return ccyHistoryPriceMapper.selectCcyHistoryPriceList(ccyHistoryPrice);
    }

    /**
     * 新增历史数据
     * 
     * @param ccyHistoryPrice 历史数据
     * @return 结果
     */
    @Override
    public int insertCcyHistoryPrice(CcyHistoryPrice ccyHistoryPrice)
    {
        return ccyHistoryPriceMapper.insertCcyHistoryPrice(ccyHistoryPrice);
    }

    /**
     * 修改历史数据
     * 
     * @param ccyHistoryPrice 历史数据
     * @return 结果
     */
    @Override
    public int updateCcyHistoryPrice(CcyHistoryPrice ccyHistoryPrice)
    {
        ccyHistoryPrice.setUpdateTime(DateUtils.getNowDate());
        return ccyHistoryPriceMapper.updateCcyHistoryPrice(ccyHistoryPrice);
    }

    /**
     * 批量删除历史数据
     * 
     * @param ids 需要删除的历史数据主键
     * @return 结果
     */
    @Override
    public int deleteCcyHistoryPriceByIds(Long[] ids)
    {
        return ccyHistoryPriceMapper.deleteCcyHistoryPriceByIds(ids);
    }

    /**
     * 删除历史数据信息
     * 
     * @param id 历史数据主键
     * @return 结果
     */
    @Override
    public int deleteCcyHistoryPriceById(Long id)
    {
        return ccyHistoryPriceMapper.deleteCcyHistoryPriceById(id);
    }
}
